package com.jgp.security.controller;

import com.jgp.security.secmodel.SecGivePower;
import com.jgp.security.service.SecGivePowerService;
import com.jgp.sys.controller.JGPBackController;
import com.jgp.sys.ui.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 项目   jgp-cloud-parent
 * 作者   loufei
 * 时间   2022/2/17
 */
@RestController
@RequestMapping("/security/data-power-api-ctl")
public class DataPowerApiController extends JGPBackController {
	
	
	@Autowired
	private SecGivePowerService givePowerService;
	
	@RequestMapping("query-with-institution")
	private Result queryAuthorizationWithInstitution(String userId) {
		List<SecGivePower> authorizations = givePowerService.queryAuthorizationWithInstitution(userId);
		return ajaxRe(true).addData("authorizations", authorizations.stream().map(secGivePower -> Long.parseLong(secGivePower.getProvider())).collect(Collectors.toList()));
	}
	
	@RequestMapping("grant-with-institution")
	private Result grantAuthorizationWithInstitution(String[] institutionIds, String userId) {
		givePowerService.grantAuthorizationWithInstitution(Arrays.asList(institutionIds), userId);
		return ajaxRe(true);
	}
}
